# 论坛首页自动化测试
from selenium.common import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from ForumAutoTest.Common.Utils import ForumDriver





class ForumHomePage:
    driver = ""
    url = ""

    def __init__(self):
        self.driver = ForumDriver.driver
        self.url = "http://127.0.0.1:58080/index.html"
        self.driver.get(self.url)

    #登陆状态
    def HomeLoginSu(self):
        # 检查论坛首页各个功能模块
        # 点击Java
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(2)").click()
        sleep(1)
        # 截图--1
        ForumDriver.getScreeShot()

        # 点击c++
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(3)").click()
        sleep(1)
        # 截图--2
        ForumDriver.getScreeShot()

        # 点击前端技术
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(4)").click()
        sleep(1)
        # 截图--3
        ForumDriver.getScreeShot()

        # 点击MysSQL
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(5)").click()
        sleep(1)
        # 截图--4
        ForumDriver.getScreeShot()

        # 点击面试宝典
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(6)").click()
        sleep(1)
        # 截图--5
        ForumDriver.getScreeShot()

        # 点击经验分享
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(7)").click()
        sleep(1)
        # 截图--6
        ForumDriver.getScreeShot()

        # 点击招聘信息
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(8)").click()
        sleep(1)
        # 截图--7
        ForumDriver.getScreeShot()

        # 点击福利待遇
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(9)").click()
        sleep(1)
        # 截图--8
        ForumDriver.getScreeShot()

        # 点击灌输区
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(10)").click()
        sleep(1)
        # 截图--9
        ForumDriver.getScreeShot()

        # 点击首页
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a > span.nav-link-title").click()
        sleep(1)
        # 截图--10
        ForumDriver.getScreeShot()




        # 找到比特论坛logo
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1 > a > img")

        # 点击搜索框，输入内容
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none >"
                                                  " div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input").send_keys("测试",Keys.ENTER)
        sleep(1)
        # 截图--11
        ForumDriver.getScreeShot()

        # 点击切换至黑夜模式
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > "
                                                  "header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div >"
                                                  " div:nth-child(2) > a.nav-link.px-0.hide-theme-dark").click()
        sleep(1)
        # 截图--12
        ForumDriver.getScreeShot()

        # 点击切换至白天模式
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div >"
                                                  " div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light").click()
        sleep(1)
        # 截图--13
        ForumDriver.getScreeShot()

        #点击小铃铛
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none "
                                                  "> div > div > div:nth-child(2) > div > a > svg").click()
        sleep(1)
        #站内信息回复
        # 截图--14
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#index_div_message_list > div > div > div:nth-child(3)").click()
        sleep(1)
        # 截图--15
        ForumDriver.getScreeShot()

        #取消回复
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_cancel").click()
        sleep(15)
        # 截图--16
        ForumDriver.getScreeShot()



        #重新点击并回复
        self.driver.find_element(By.CSS_SELECTOR, "#index_div_message_list > div > div > div:nth-child(3)").click()
        sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_message_reply > svg").click()
        sleep(2)

        # 截图--17
        ForumDriver.getScreeShot()
        #定位要回复的人
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_receive_user_name")
        #回复有内容
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_receive_content").send_keys("好的好的")
        sleep(1)

        # 截图--18
        ForumDriver.getScreeShot()
        #点击发送
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message_reply > svg").click()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        print(warning_message)
        assert "操作成功" in warning_message
        # 添加屏幕截图--19
        ForumDriver.getScreeShot()


        # 重新点击并且回复内容为空
        self.driver.find_element(By.CSS_SELECTOR, "#index_div_message_list > div > div > div:nth-child(3)").click()
        sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_message_reply > svg").click()
        # 定位要回复的人
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_receive_user_name")
        # 回复没有有内容
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_receive_content").clear()
        sleep(1)

        # 截图--20
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message_reply > svg").click()
        sleep(1)
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        print(warning_message)
        assert "请输入要回复的内容" in warning_message
        # 截图--21
        ForumDriver.getScreeShot()

        #关闭站内信息
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_offcanvasEnd > div.offcanvas-header > button").click()
        sleep(1)
        # 截图--22
        ForumDriver.getScreeShot()


        #点击用户头像
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        sleep(1)
        # 截图--23
        ForumDriver.getScreeShot()

        sleep(2)

        #点击我的帖子
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_profile").click()
        sleep(2)
        # 截图--24
        ForumDriver.getScreeShot()

        #点击自己的帖子
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li > div.card.timeline-event-card >"
                                                     " div > div > div > div > div.text-truncate > a").click()
        sleep(2)
        # 截图--25
        ForumDriver.getScreeShot()

        #点赞
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count").click()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div").text
        print(warning_message)
        assert "点赞成功" in warning_message
        # 截图--26
        ForumDriver.getScreeShot()

        #点击编辑
        self.driver.find_element(By.CSS_SELECTOR, "#details_artile_edit").click()
        sleep(3)
        # 截图--27
        ForumDriver.getScreeShot()

        #修改一下标题与内容
        self.driver.find_element(By.CSS_SELECTOR, "#edit_article_title").send_keys("随便加一点")
        sleep(3)
        try:
            self.driver.find_element(By.CSS_SELECTOR, "#edit_article_content_area > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll").send_keys("随便加一点")
        except Exception as e:
            print("无法修改内容")

        sleep(1)
        # 截图--28
        ForumDriver.getScreeShot()

        # 提交
        # 无法正常提交
        # 绕过浏览器 UI 层，直接在 DOM 层派发事件，破解所有 “元素被遮挡”
        # 1) 强制移除遮挡层
        self.driver.execute_script("""
                    document.querySelectorAll('.jq-toast-wrap, .offcanvas').forEach(el => el.remove());
                """)

        # 2) JS 强制点击按钮
        submit = WebDriverWait(self.driver, 5).until(
            EC.presence_of_element_located((By.ID, "edit_article_submit"))
        )
        self.driver.execute_script("arguments[0].click();", submit)

        # 3) 等待 Toast 出现并断言
        toast = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, ".jq-toast-single"))
        )
        assert "修改成功" in toast.text
        print(toast.text)
        # 截图--29
        ForumDriver.getScreeShot()


        # 点击个人
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # 点击个人中心
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        sleep(1)
        # 截图--30
        ForumDriver.getScreeShot()

        #修改该头像就不测了，之前也说了有Bug
        #修改昵称
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").send_keys("tired66")
        sleep(3)
        # 截图--31
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,
                                                   "body > div.jq-toast-wrap.bottom-right > div").text
        print("修改昵称：" + warning_message)
        assert "操作成功" in warning_message
        # 截图--32
        ForumDriver.getScreeShot()

        sleep(1)

        # 修改邮箱
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").send_keys("1234567@qq.com")
        sleep(1)
        # 截图--33
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,
                                                   "body > div.jq-toast-wrap.bottom-right > div").text
        print("修改邮箱："+"/" +warning_message)
        assert "操作成功" in warning_message
        # 截图--34
        ForumDriver.getScreeShot()

        sleep(1)

        # 修改电话
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").send_keys(
            "88888888")
        # 截图--35
        ForumDriver.getScreeShot()
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_phoneNum").click()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,
                                                   "body > div.jq-toast-wrap.bottom-right > div").text
        print("修改电话："+"/" +warning_message)
        assert "操作成功" in warning_message
        # 截图--36
        ForumDriver.getScreeShot()

        sleep(3)
        # 修改密码，输入的原密码不正确
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("adadad")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("666")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("666")

        submit = self.driver.find_element(By.ID, "settings_submit_password")
        self.driver.execute_script("arguments[0].click();", submit)
        sleep(1)
        # 截图--37
        ForumDriver.getScreeShot()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,
                                                   "body > div.jq-toast-wrap.bottom-right > div").text
        print("修改密码：" +warning_message)
        assert "参数校验失败" in warning_message
        sleep(1)
        # 截图--38
        ForumDriver.getScreeShot()

        sleep(5)
        # 修改密码，输入两次新密码不同
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("666")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("777")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("777777")

        submit = self.driver.find_element(By.ID, "settings_submit_password")
        self.driver.execute_script("arguments[0].click();", submit)
        sleep(1)
        # 截图--39
        ForumDriver.getScreeShot()
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,
                                                   "body > div.jq-toast-wrap.bottom-right > div").text
        print("修改密码" +warning_message)
        assert "两次输入的密码不相同" in warning_message
        sleep(1)
        # 截图--40
        ForumDriver.getScreeShot()

        sleep(1)

        #修改个人简介
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").send_keys("唱，跳，rap，打篮球")
        sleep(1)
        # 截图--41
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_remark").click()
        toast = WebDriverWait(self.driver, 5).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, ".jq-toast-single"))
        )
        print("修改简介："+warning_message)
        assert "操作成功" in toast.text
        sleep(1)
        # 截图--42
        ForumDriver.getScreeShot()

        # 正常修改密码
        # 修改密码，输入两次新密码不同
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("666")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("777")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("777")

        submit = self.driver.find_element(By.ID, "settings_submit_password")
        self.driver.execute_script("arguments[0].click();", submit)
        sleep(1)
        # 截图--43
        ForumDriver.getScreeShot()

        #重新登录
        # 定位用户登录页元素
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div.page.page-center > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
        # 确保用户与密码框为空
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        # 定位到用户名输入框，输入正确的账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("666")
        sleep(1)
        # 定位到用户密码输入框，输入正确的密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("777")
        sleep(1)
        # 定位到登录按钮并且点击
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        # 判断是否登录成功,成功即可定位到以下元素，并且截图查看
        # 定位论坛板块导航
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header:nth-child(2)")
        # 定位正文部分
        self.driver.find_element(By.CSS_SELECTOR, "#page-wrapper")

        # 截图--44
        ForumDriver.getScreeShot()
        sleep(1)
        #返回首页
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()

        sleep(1)
        # 截图--45
        ForumDriver.getScreeShot()

        # 点击个人
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # 点击个人中心
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        # 正常修改密码，将密码改回
        # 修改密码，输入两次新密码不同
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("777")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("666")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("666")

        submit = self.driver.find_element(By.ID, "settings_submit_password")
        self.driver.execute_script("arguments[0].click();", submit)
        sleep(1)
        # 截图--46
        ForumDriver.getScreeShot()

        # 重新登录
        # 定位用户登录页元素
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div.page.page-center > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
        # 确保用户与密码框为空
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        # 定位到用户名输入框，输入正确的账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("666")
        sleep(1)
        # 定位到用户密码输入框，输入正确的密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("666")
        sleep(1)
        # 定位到登录按钮并且点击
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        # 判断是否登录成功,成功即可定位到以下元素，并且截图查看
        # 定位论坛板块导航
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header:nth-child(2)")
        # 定位正文部分
        self.driver.find_element(By.CSS_SELECTOR, "#page-wrapper")


        # 发布空内容帖子
        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > "
                                                  "div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > "
                                                  "div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        sleep(1)
        # 幕截图--47
        ForumDriver.getScreeShot()
        # 选择板块
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(7)").click()
        # 添加标题与内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("自动化发布")
        # 截图--48
        ForumDriver.getScreeShot()

        # 提交
        # 绕过浏览器 UI 层，直接在 DOM 层派发事件，破解所有 “元素被遮挡”
        # 1) 强制移除遮挡层
        self.driver.execute_script("""
                                           document.querySelectorAll('.jq-toast-wrap, .offcanvas').forEach(el => el.remove());
                                       """)

        # 2) JS 强制点击按钮
        submit = WebDriverWait(self.driver, 5).until(
            EC.presence_of_element_located((By.ID, "article_post_submit"))
        )
        self.driver.execute_script("arguments[0].click();", submit)
        wait = WebDriverWait(self.driver, 2)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")))
        warning_message = self.driver.find_element(By.CSS_SELECTOR,
                                                   "body > div.jq-toast-wrap.bottom-right > div").text
        print("发布帖子："+ warning_message)
        assert "请输入帖子内容" in warning_message
        sleep(1)
        # 截图--49
        ForumDriver.getScreeShot()

        # 重回首页
        # 点击首页
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()
        # 发布帖子
        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > "
                                                  "div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > "
                                                  "div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        sleep(1)
        # 截图--50
        ForumDriver.getScreeShot()
        # 选择板块
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(7)").click()
        # 添加标题与内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("自动化发布")
        self.driver.execute_script("""
                                            document.querySelectorAll('.jq-toast-wrap, .offcanvas').forEach(el => el.remove());
                                        """)

        # 等待真正的隐藏 textarea
        editor = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, "#edit-article .CodeMirror textarea"))
        )

        # 聚焦 + 输入
        self.driver.execute_script("arguments[0].focus();", editor)
        editor.send_keys("自动化")
        # 截图--51
        ForumDriver.getScreeShot()

        sleep(3)
        # 提交
        # 无法正常提交
        # 绕过浏览器 UI 层，直接在 DOM 层派发事件，破解所有 “元素被遮挡”
        # 1) 强制移除遮挡层
        self.driver.execute_script("""
                                    document.querySelectorAll('.jq-toast-wrap, .offcanvas').forEach(el => el.remove());
                                """)

        # 2) JS 强制点击按钮
        submit = WebDriverWait(self.driver, 5).until(
            EC.presence_of_element_located((By.ID, "article_post_submit"))
        )
        self.driver.execute_script("arguments[0].click();", submit)

        # 3) 等待 Toast 出现并断言
        toast = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, ".jq-toast-single"))
        )
        print("发布帖子："+toast.text)
        assert "发帖成功" in toast.text

        # 截图--52
        ForumDriver.getScreeShot()

        sleep(2)
        # 点击个人
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # 退出登录
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_logout").click()
        sleep(1)
        # 截图--53
        ForumDriver.getScreeShot()

    #未登录状态下访问首页
    def HomeLoginFail(self):
        #重进登录页
        self.driver.get("http://127.0.0.1:58080/sign-in.html")
        self.driver.get("http://127.0.0.1:58080/index.html")
        try:
            WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, "#nav_board_index > a")
                )
            )
            print("页面加载完成，找到了指定元素")
        except TimeoutException:
            print("超时：页面未加载完成或未找到指定元素")
            # 截图--1
            ForumDriver.getScreeShot()
            sleep(1)
